home *** CD-ROM | disk | FTP | other *** search
- Path: chaos.kulnet.kuleuven.ac.be!usenet
- From: Peter.Vanovertveldt@cc.kuleuven.ac.be (PeterV)
- Newsgroups: comp.lang.c++
- Subject: polyformism
- Date: Thu, 21 Mar 1996 13:18:29 GMT
- Organization: KULeuven
- Message-ID: <4irl0e$qg1@chaos.kulnet.kuleuven.ac.be>
- NNTP-Posting-Host: ipv13006.cc.kuleuven.ac.be
- X-Newsreader: Forte Free Agent 1.0.82
-
- I have the following question:
- How can I use call by value in a function call, when I'm using
- polyformism ?
-
- class Base
- (
- ....
- );
- class Deriv1: public Base
- (
- ....
- );
- class Deriv2: public Base
- (
- .....
- );
- main()
- (
- Base *pointer;
- pointer=new Deriv1;
- fun(pointer);
- )
- fun(Base *p)
- (
- // I would like to edit the object at which p points at
- without changing the original object.
- )
-
- To declare the new operator virtual, would be a solution; but virtual
- operators aren't possible ! ex. Base *pbis;
- pbis=new (*p); // and hope that Pbis points at a copy of the original
- object.
- Make a virtual copy function would be a solution too but I think it's
- a bad one.
- I would like to make sure that the fun function is independent from
- future derived classes form the Base class, ex Deriv3.
-
-